<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="reportTitle" value="自动点巡检报表" />

<%@ include file="/common/report_head.jsp" %>
<%@ include file="/condition/sartTime_input.html"%>
<%@ include file="/condition/endTime_input.html"%>
<%@ include file="/condition/fab_sumo_must.html"%>
<%@ include file="/condition/line_sumo.html"%>
<%@ include file="/condition/toolg_sumo.html"%>
<%@ include file="/condition/toolType_radio.html"%>
<%@ include file="/condition/tool_sumo.html"%>

<%@ include file="/common/report_middle.jsp" %>
<div class="col-md-12" style="height: 820px;">
    <div id="pqGrid"></div>
</div>
<%@include file="/common/report_end.jsp" %>

<script>
    $(document).ready(function () {
        $("title").text("自动点巡检报表");

        $('#query_btn').click(query_ajax);

        function query_ajax(){
            initGridAndChart();
            ajax('/jn-report/report/retAutoIns_report.do' ,loadConditionMapData(), true, ajax_successful);

            function ajax_successful(outTrxObj) {
                if(outTrxObj.gridData.length < 1) { showMessengerDialog("数据查询为空"); return false; }

                if ($("#pqGrid").length > 0) {
                    // Grid表格动态列
                    var colM = [
                        {dataIndx: "state",align: "center",
                            title: "<input type='checkbox' />",
                            cb: { header: true, select: true, all: true },
                            type: 'checkbox',
                            //cls: 'ui-state-default',
                            dataType: 'bool',
                            editor: false,
                            exportRender: false
                        },
                        {halign:"center",align:'center', dataIndx: 'begin_timestamp',  	 title: '点检时间',    width: 220,   editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'fab_id',	         title: '厂别',        width: 150,   editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'fab_id_fk',	         title: '厂别',        width: 150,   editable: false, sortable: true, hidden: true},
                        {halign:"center",align:'center', dataIndx: 'line_id',      	     title: '线别',        width: 150,   editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'line_id_fk',      	 title: '线别',        width: 150,   editable: false, sortable: true, hidden: true},
                        {halign:"center",align:'center', dataIndx: 'tool_id',       	 title: '设备代码',    width: 220,   editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'tool_id_fk',    	 title: '设备代码',    width: 220,   editable: false, sortable: true, hidden: true},
                        {halign:"center",align:'center', dataIndx: 'determine_flg',  	 title: '确认状态',    width: 70,    editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'determine_usr',  	 title: '确认人',      width: 100,   editable: false, sortable: true},
                        {halign:"center",align:'center', dataIndx: 'determine_timestamp',title: '确认时间',    width: 220,   editable: false, sortable: true}];
                    for (var i=0; i<outTrxObj.dynamicColumn.length; i++){
                        var data_group = outTrxObj.dynamicColumn[i];
                        colM.push({halign:'center', align:'center',  dataIndx: data_group, title: data_group, width: 230, editable: false, sortable: true});
                    }

                    var conf = {
                        toolbar: {
                            items: [
                                {
                                    type: 'button',
                                    width: 150,
                                    label: "导出Excel",
                                    icon: 'ion-ios-download-outline',
                                    listener: function () {
                                        //var format = 'xls',
                                        //    blob = this.exportData({
                                        //        format: format,
                                        //        render: true
                                        //    });
                                        //if (typeof blob === "string") {
                                        //    blob = new Blob([blob]);
                                        //}
                                        var format = 'xlsx',
                                            blob = this.exportData({
                                                format: format,
                                                render: true,
                                                type: 'blob'
                                            });
                                        var excel_name = "Report_Excel.";
                                        if (this.options.title != null && this.options.title != "" && this.options.title != 'undefined') {
                                            excel_name = this.options.title + ".";
                                        }
                                        saveAs(blob, excel_name + format);
                                    }
                                }, {
                                    type: "<span>共 0 条</span>",
                                    width: 110
                                }, {
                                    type: 'button',
                                    width: 150,
                                    label: "点巡检确认",
                                    icon: 'ion-ios-download-outline',
                                    listener: function () {
                                        var ids = $("#pqGrid").pqGrid("Selection").that.SelectRow().getSelection();
                                        var iaryI = [];
                                        if (ids.length <= 0) {
                                            showErrorDialog("", "请选择要确认的数据！");
                                            return false;
                                        } else {
                                            for (var i = 0; i < ids.length; i++) {
                                                iaryI.push({
                                                    begin_timestamp: ids[i].rowData.begin_timestamp,
                                                    fab_id_fk: ids[i].rowData.fab_id_fk,
                                                    line_id_fk: ids[i].rowData.line_id_fk,
                                                    tool_id_fk: ids[i].rowData.tool_id_fk
                                                });
                                            }
                                            var inTrxObj = {
                                                trx_id: 'XPRETAUTOINS',
                                                action_flg: 'U',
                                                determine_flg: 'Y',
                                                determine_usr: $("#userSpan").text(),
                                                iary: iaryI
                                            };
                                            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
                                            if (outTrxObj.rtn_code == "0000000") {
                                                query_ajax('/jn-report/report/retAutoIns_report.do');
                                                showSuccessDialog("确认成功");
                                            }
                                        }
                                    }
                                }
                            ]
                        },
                        colModel:colM
                    };
                    _pqUtil.f.destroy($("#pqGrid"));
                    _pqUtil.f.createGrid($("#pqGrid"), conf);
                    _pqUtil.f.seTitle($("#pqGrid"), outTrxObj.gridTitle);
                    _pqUtil.f.loadPqGridData($("#pqGrid"), outTrxObj.dynamicColumnJsonGridData);
                }
            }
        }

    });
</script>
